itss: Replace malloc() with HeapAlloc()

Francois Gouget fgouget at free.fr
Tue Feb 10 06:22:10 CST 2009


On Tue, 10 Feb 2009, Nikolay Sivov wrote:
[...]
> Why didn't you replace corresponding free() calls?

Also, for everyone's information, there's more calls to malloc() and 
free(). I only grepped in the dlls/ directory where they are the most 
suspicious. I removed some obvious false positives but there may be 
more. Here's what I got:

dlls/itss/lzx.c:181:    pState = malloc(sizeof(struct LZXstate));
dlls/itss/lzx.c:182:    if (!(pState->window = malloc(wndsize)))
dlls/rsaenh/mpi.c:157:  a->dp = malloc (sizeof (mp_digit) * MP_PREC);
dlls/rsaenh/mpi.c:185:  a->dp = malloc (sizeof (mp_digit) * size);
dlls/rsaenh/mpi.c:3381:   tmp = malloc(bsize);
dlls/twain_32/dsm_ctrl.c:89:			devices = malloc(sizeof(devices[0]));
dlls/winedos/dosconf.c:267:        DOSCONF_config.country = malloc(strlen(*confline) + 1);
dlls/winedos/dosconf.c:307:        DOSCONF_config.shell = malloc(strlen(*confline) + 1);
dlls/winedos/dosconf.c:370:        DOSCONF_menu_default = malloc(strlen(*confline) + 1);
dlls/winedos/dosconf.c:387:    temp = malloc(strlen(*confline) + 1);
dlls/winedos/dosvm.c:260:    event = malloc(sizeof(DOSEVENT));
dlls/winedos/ppdev.c:184:	PPDeviceList[nports].devicename = malloc(sizeof(buffer)+1);
dlls/winemp3.acm/interface.c:74:	nbuf = malloc( sizeof(struct buf) );
dlls/winemp3.acm/interface.c:79:	nbuf->pnt = malloc(size);
dlls/winenas.drv/audio.c:1383:        void *newbuf = malloc(wwo->BufferUsed + len);
dlls/winenas.drv/audio.c:1418:     ptr = malloc(len);
dlls/winenas.drv/audio.c:1420:     newdata = malloc(wwo->BufferUsed - len);
dlls/winhttp/net.c:634:     * SSL 0.9.7 and above malloc the buffer if it is null.
dlls/winhttp/net.c:653:    if (malloc) free( buffer );

dlls/ddraw/tests/ddrawmodes.c:95:	modes = malloc((modes_size = 2) * sizeof(DDSURFACEDESC));
dlls/dsound/tests/ds3d.c:51:    b=buf=malloc(*size);
dlls/lz32/tests/lzexpand_main.c:884:  buf = malloc(uncompressed_data_size * 2);
dlls/oleaut32/tests/vartype.c:35:#    include <malloc.h>
dlls/rpcrt4/tests/server.c:1202:  dc = malloc(FIELD_OFFSET(doub_carr_t, a[2]));
dlls/rpcrt4/tests/server.c:1204:  dc->a[0] = malloc(FIELD_OFFSET(doub_carr_1_t, a[3]));
dlls/rpcrt4/tests/server.c:1209:  dc->a[1] = malloc(FIELD_OFFSET(doub_carr_1_t, a[2]));
dlls/rpcrt4/tests/server.c:56:  return malloc(n);
dlls/shell32/tests/shlexec.c:336:        cmd=malloc(strlen(argv0)+10+strlen(child_file)+2+strlen(cmdtail)+1);

dlls/dbghelp/msc.c:2480:                free(files_image);
dlls/itss/lzx.c:184:        free(pState);
dlls/itss/lzx.c:220:        free(pState->window);
dlls/itss/lzx.c:221:        free(pState);
dlls/ntdll/server.c:752:            free( tmp_dir );
dlls/rsaenh/mpi.c:217:    free(a->dp);
dlls/rsaenh/mpi.c:3446:   free(tmp);
dlls/winedos/dosconf.c:357:            free(DOSCONF_menu_default);
dlls/winedos/dosconf.c:390:    free(temp);
dlls/winedos/dosvm.c:185:        free(event);
dlls/winedos/dosvm.c:625:            free(event);
dlls/winedos/int33.c:221:  free(data);
dlls/winejack.drv/audio.c:2006:        free(ports); /* free the returned array of ports */
dlls/winejack.drv/audio.c:735:        free(ports); /* free the returned array of ports */
dlls/winemp3.acm/interface.c:115:  free(buf->pnt);
dlls/winemp3.acm/interface.c:116:  free(buf);
dlls/winemp3.acm/interface.c:60:		free(b->pnt);
dlls/winemp3.acm/interface.c:62:		free(b);
dlls/winemp3.acm/interface.c:81:		free(nbuf);
dlls/winenas.drv/audio.c:1387:        free(oldbuf);
dlls/winenas.drv/audio.c:1432: free(ptr);
dlls/wininet/netconnection.c:753:        free(buffer);

dlls/ddraw/tests/ddrawmodes.c:104:    free(modes);
dlls/dsound/tests/ds3d8.c:521:        free(state.wave);
dlls/dsound/tests/ds3d.c:677:        free(state.wave);
dlls/lz32/tests/lzexpand_main.c:889:  free(buf);
dlls/ntdll/tests/rtlstr.c:1367:	free(wstr);
dlls/ntdll/tests/rtlstr.c:1407:    free(wstr);
dlls/ntdll/tests/rtlstr.c:296:    free(teststring2);
dlls/rpcrt4/tests/server.c:1214:  free(dc->a[0]);
dlls/rpcrt4/tests/server.c:1215:  free(dc->a[1]);
dlls/rpcrt4/tests/server.c:1216:  free(dc);
dlls/rpcrt4/tests/server.c:62:  free(p);
dlls/shell32/tests/shlexec.c:340:        free(cmd);


Notes:
 * It's probably not as bad to use malloc() in tests but it should still 
   be avoided.
 * Using #include <malloc.h> when not using malloc is wrong.
 * Some calls to malloc() and free() may be required by the Unix APIs 
   that are called. This should be checked on a case by case basis.
 * If the above don't have too many false positives I could integrate 
   that check into my scripts.

-- 
Francois Gouget <fgouget at free.fr>              http://fgouget.free.fr/
        A polar bear is a cartesian bear after a coordinate transform.



More information about the wine-devel mailing list